//
//  SecondViewController.m
//  Demo
//
//  Created by 龚碧容 on 2017/9/15.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "SecondViewController.h"
#import "QLMOrderTabCell.h"
#import "QLMIntroManDetailTabCell.h"
#import "QLMBXOrderListVC.h"
#import "QLMBXOrderDetailVC.h"
#import "QLMOrderListArrModel.h"
#import "QLMEvaluationVC.h"
#import "QLMAddBaoxiuVC.h"
#import "QLMServiceManInfoModel.h"
#import "QLMServicemanListVC.h"
#import "QLMServiceManDetailVC.h"

#import "QLMBXOrderListTabVCell.h"

@interface SecondViewController ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>{
    QLMOrderListArrModel *orderListArrModel;
    QLMServiceManInfoModel *serviceInfoModel;

    QLMCustomTipView *tipView;
    QLMCustomTipView *tipView2;
    
    BMKLocationService *_locService;
    BMKGeoCodeSearch *_geocodesearch;
}

@property (nonatomic,strong) UIImageView *navBarHairlineImageView;
@property (nonatomic,strong) UITableView *stableview;
@property (nonatomic,strong) UITableView *mantableview;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationController.view.backgroundColor=[UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1];
    self.title=@"报修";
    
    serviceInfoModel.data=[NSMutableArray array];
    orderListArrModel.orders=[NSMutableArray array];
    
    _navBarHairlineImageView = [ClientTool findHairlineImageViewUnder:self.navigationController.navigationBar];
    [self _creatTopButtonAction];
    
    _stableview=[[UITableView alloc] initWithFrame:CGRectMake(0, QLM_StatusBarAndNavigationBarHeight, kScreen_width, (kScreen_height-QLM_StatusBarAndNavigationBarHeight-49-2)/2) style:UITableViewStyleGrouped];
    _stableview.backgroundColor=[UIColor clearColor];
    _stableview.delegate=self;
    _stableview.dataSource=self;
    _stableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    _stableview.showsVerticalScrollIndicator=NO;
    _stableview.showsHorizontalScrollIndicator=NO;
    _stableview.tableFooterView=[UIView new];
    [self.view addSubview:_stableview];
    
    _mantableview=[[UITableView alloc] initWithFrame:CGRectMake(0, _stableview.frame.origin.y+_stableview.frame.size.height, kScreen_width, _stableview.frame.size.height) style:UITableViewStylePlain];
    _mantableview.backgroundColor=[UIColor clearColor];
    _mantableview.delegate=self;
    _mantableview.dataSource=self;
    _mantableview.tag=666;
    _mantableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    _mantableview.showsVerticalScrollIndicator=NO;
    _mantableview.showsHorizontalScrollIndicator=NO;
    _mantableview.tableFooterView=[UIView new];
    [self.view addSubview:_mantableview];
    
    tipView=[QLMCustomTipView sharedInstance];
    tipView.hidden = YES;
    [_stableview addSubview:tipView];
    
    tipView2=[QLMCustomTipView sharedInstance];
    tipView2.hidden = YES;
    [_mantableview addSubview:tipView2];
    
    _geocodesearch = [[BMKGeoCodeSearch alloc]init];
    _locService = [[BMKLocationService alloc]init];//定位功能的初始化
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)presentaLoginVC{
    QLMLoginViewController *loginController = [QLMLoginViewController new];
    loginController.resultBlock=^(BOOL success){};
    QLMCustomNavCtr *nav=[[QLMCustomNavCtr alloc] initWithRootViewController:loginController];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    _navBarHairlineImageView.hidden=YES;
    self.navigationController.navigationBarHidden=YES;
  
    _geocodesearch.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    [self _startLocation];
    
    if (![[UserManager sharedManager] isUserLogin]) {//判断是否登录
        [self presentaLoginVC];
    }else{
        [self requestOrderListData];
    }
  
    [MobClick beginLogPageView:self.title];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    _navBarHairlineImageView.hidden=NO;
    
    [_locService stopUserLocationService];
    _locService.delegate = nil;
    _geocodesearch.delegate = nil; // 不用时，置nil
    
    [MobClick endLogPageView:self.title];
}

- (void)_startLocation{
    _locService.delegate = self;//设置代理位self
    [_locService startUserLocationService];//启动定位服务
}
#pragma mark - BMKLocationServiceDelegate
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    [_locService stopUserLocationService];

    NSDictionary *enddic=[NSDictionary dictionaryWithObjectsAndKeys:@(userLocation.location.coordinate.latitude),@"latitu",@(userLocation.location.coordinate.longitude),@"longtitu", nil];
    [[NSUserDefaults standardUserDefaults] setObject:enddic forKey:@"enddic"];
    
    [self requestServiceManData:userLocation.location.coordinate.latitude withLong:userLocation.location.coordinate.longitude];
    
    //地理反编码
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    if(flag){
        NSLog(@"反geo检索发送成功");
        [_locService stopUserLocationService];
    }else{
        NSLog(@"反geo检索发送失败");
    }
}

-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    BMKAddressComponent *addressDetail=result.addressDetail;
    NSString *detailAddr=[NSString stringWithFormat:@"%@%@%@%@%@",addressDetail.province,addressDetail.city,addressDetail.district,addressDetail.streetName,addressDetail.streetNumber];
    [[NSUserDefaults standardUserDefaults] setObject:detailAddr forKey:@"detailAddr"];
}

//定位失败
- (void)didFailToLocateUserWithError:(NSError *)error{
        NSLog(@"error:%@",error);
}

#pragma mark -
- (void)_creatTopButtonAction{
    
    UIView *topBackView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, QLM_StatusBarAndNavigationBarHeight)];
    topBackView.backgroundColor=kNavigationBarColor;
    [self.view addSubview:topBackView];
    
    UIButton *leftBtn=[self acreatButton:CGRectMake(10, topBackView.frame.size.height-34-5, kScreen_width/2-15, 34) title:@"在线报修" image:@"bx_zaixian"];
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    leftBtn.titleLabel.font=[UIFont systemFontOfSize:17.f];
    leftBtn.layer.masksToBounds=YES;
    leftBtn.layer.cornerRadius=3.0f;
    leftBtn.layer.borderWidth=1.0f;
    leftBtn.layer.borderColor=[UIColor whiteColor].CGColor;
    leftBtn.tag=550;
    [self.view addSubview:leftBtn];
    
    UIButton *rightBtn=[self acreatButton:CGRectMake(kScreen_width/2+5, leftBtn.frame.origin.y, kScreen_width/2-15, 34) title:@"400报修" image:@"bx_400"];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font=[UIFont systemFontOfSize:17.f];
    rightBtn.layer.masksToBounds=YES;
    rightBtn.layer.cornerRadius=3.0f;
    rightBtn.layer.borderWidth=1.0f;
    rightBtn.layer.borderColor=[UIColor whiteColor].CGColor;
    rightBtn.tag=551;
    [self.view addSubview:rightBtn];
}

- (NSString *)resultString:(NSString *)classificationId{
    NSString *classificationStr=nil;
    switch ([classificationId integerValue]) {
        case 0:
            classificationStr=@"发动机";
            break;
        case 1:
            classificationStr=@"电气";
            break;
        case 2:
            classificationStr=@"液压";
            break;
        case 3:
            classificationStr=@"其他";
            break;
        case 4:
            classificationStr=@"保养";
            break;
        default:
            break;
    }
    return classificationStr;
}

- (NSString *)resultStatus:(QLMOrderListInfoModel *)resultInfoModel{
    NSString *orderStatusStr=nil;
    switch ([resultInfoModel.orderStatus integerValue]) {
        case 0:
            orderStatusStr=@"待派工";
            break;
        case 1:
            orderStatusStr=@"已派工";
            break;
        case 2:
            orderStatusStr=@"已预约";
            break;
        case 3:
            orderStatusStr=@"已出发";
            break;
        case 4:
            orderStatusStr=@"已到达";
            break;
        case 5:
            if ([resultInfoModel.erpOrderStatus integerValue]==0) {
                orderStatusStr=@"待支付(服务结束)";
            }else if ([resultInfoModel.erpOrderStatus integerValue]==1){
                orderStatusStr=@"支付中";
            }else if ([resultInfoModel.erpOrderStatus integerValue]==2){
                
                orderStatusStr=@"已评价";
                if ([resultInfoModel.isEvaluation integerValue]==0) {
                    orderStatusStr=@"待评价";
                }
                
            }else if ([resultInfoModel.erpOrderStatus integerValue]==3){
                orderStatusStr=@"支付失败";
            }else{
                orderStatusStr=@"已结束";
            }
            
            break;
        case 6:
            orderStatusStr=@"已中断";
            break;
        case 7:
            orderStatusStr=@"中断出发";
            break;
        default:
            break;
    }
    return orderStatusStr;
}

#pragma mark - request data
- (void)requestOrderListData{
    
    [orderListArrModel.orders removeAllObjects];
    
    NSString *token=[[NSUserDefaults standardUserDefaults] objectForKey:kLoginToken];
    NSDictionary *tokenDic=[NSDictionary dictionaryWithObjectsAndKeys:token,@"token", nil];
    if ([token length]==0) {
        [_stableview reloadData];
        return;
    }
    
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:@"" forKey:@"equipmentId"];
    
    [paramerDic setObject:@"1" forKey:@"page"];
    [paramerDic setObject:@"3" forKey:@"rows"];
    
    //    /test/repairOrder/getOrder
    [self.view makeToastActivity:CSToastPositionCenter];
    [ClientTool postUrlPath:@"/test/repairOrder/getOrderList" withParamers:paramerDic andBody:tokenDic
                    success:^(id responseObject){
                        [self.view hideToastActivity];
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            orderListArrModel=[[QLMOrderListArrModel alloc] init];
                            orderListArrModel.orders=[NSMutableArray arrayWithArray:responseObject[@"orders"]];
                            
                            if (orderListArrModel.orders.count==0) {
                                tipView.hidden = NO;
                            }else{
                                tipView.hidden = YES;
                            }
                            [_stableview reloadData];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        [self.view hideToastActivity];
                        ETToast(@"服务器连接失败");
                    }
     ];
}

- (void)requestServiceManData:(CLLocationDegrees)latitude withLong:(CLLocationDegrees)longtitude{
    
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSString *latStr=[NSString stringWithFormat:@"%.6f",latitude];
    NSString *longStr=[NSString stringWithFormat:@"%.6f",longtitude];
    
    [dic setObject:latStr forKey:@"lat1"];
    [dic setObject:longStr forKey:@"lng1"];
    
    [dic setObject:@"1" forKey:@"pageSize"];
    [dic setObject:@"5" forKey:@"rows"];
    
    [ClientTool postUrlPath:@"/rest/serviceEvaluation/getAll" withParamers:dic andBody:nil
                    success:^(id responseObject){
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            
                            serviceInfoModel=[[QLMServiceManInfoModel alloc] init];
                            serviceInfoModel.data=[NSMutableArray arrayWithArray:responseObject[@"data"]];
                            
                            if (serviceInfoModel.data.count==0) {
                                tipView2.hidden = NO;
                            }else{
                                tipView2.hidden = YES;
                            }
                            [_mantableview reloadData];
                            
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        ETToast(@"服务器连接失败");
                    }
     ];
}

#pragma mark - Action
- (UIButton *)acreatButton:(CGRect)aFrame title:(NSString *)aTitle image:(NSString *)imageName{
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
    newButton.frame = aFrame;
    [newButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [newButton setTitle:aTitle forState:UIControlStateNormal];
    [newButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
    newButton.backgroundColor = [UIColor clearColor];
    newButton.titleLabel.font=[UIFont systemFontOfSize:18.0f];
    [newButton addTarget:self action:@selector(baoxiuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    return newButton;
}

- (void)baoxiuButtonAction:(UIButton *)btn{
    if (btn.tag==4000){
        QLMBXOrderListVC *bxOrderVC=[QLMBXOrderListVC new];
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:bxOrderVC animated:YES];
        self.hidesBottomBarWhenPushed=NO;
        return;
    }else if (btn.tag==4001){
        
        QLMServicemanListVC *serviceListVC=[QLMServicemanListVC new];
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:serviceListVC animated:YES];
        self.hidesBottomBarWhenPushed=NO;
        
        return;
    }else if (btn.tag==550){
        [self pushToBxVC:NO];
        return;
    }else if (btn.tag==551){
        [self telBtnAction];
        return;
    }else if (btn.tag==3100){
        [self pushToBxVC:NO];
        return;
    }else if (btn.tag==3101){
        [self pushToBxVC:YES];
        return;
    }else if (btn.tag==3102){
        return;
    }
}

- (void)pushToBxVC:(BOOL)bxBool{
    QLMAddBaoxiuVC *bxOrderDetailVC=[QLMAddBaoxiuVC new];
    bxOrderDetailVC.isBaoyangDevicebool=bxBool;
    bxOrderDetailVC.isSecondVCTobool=YES;
    self.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:bxOrderDetailVC animated:YES];
    self.hidesBottomBarWhenPushed=NO;
}

- (void)telBtnAction{
    UIActionSheet *telSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拨打电话", nil];
    telSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
    [telSheet showInView:self.view];
}

//拨打电话
- (void)callPhoneNumber{
    NSString *telNumberStr = [NSString stringWithFormat:@"tel://%@",@"4008896977"];
    UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectZero];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:telNumberStr]]];
    [self.view addSubview:webView];
}

#pragma mark - UIActionSheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0){
        [self callPhoneNumber];
    }else if(buttonIndex == 1){
        return;
    }
}

#pragma mark - UITableView datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag!=666) {
//        if (orderListArrModel.orders.count>5) {
//            return 5;
//        }
//        return orderListArrModel.orders.count;
        return 1;
    }
    
    if (serviceInfoModel.data.count>5) {
        return 5;
    }
    return serviceInfoModel.data.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView.tag!=666) {
        if (orderListArrModel.orders.count>5) {
            return 3;
        }
        return orderListArrModel.orders.count;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag!=666) {
        return 210;//59+25+25;
    }
    return 90;//59;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag!=666) {
        
        QLMBXOrderListTabVCell *cell=[QLMBXOrderListTabVCell cellWithTableView:tableView];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        if (orderListArrModel.orders.count!=0) {
            
            QLMOrderListInfoModel *orderInfoModel=[[QLMOrderListInfoModel alloc] initWithDictionary:orderListArrModel.orders[indexPath.section] error:nil];
            
            QLMequipManagerModel *equipManagerModel=orderInfoModel.equipmentManager;
            
            cell.carnameLabel.text=[NSString stringWithFormat:@"设备：%@%@",equipManagerModel.brandName,equipManagerModel.modelName];
            
            if ([equipManagerModel.serialNo length]==0) {
                cell.carNumLabel.text=[NSString stringWithFormat:@"机号：无"];
            }else{
                cell.carNumLabel.text=[NSString stringWithFormat:@"机号：%@",equipManagerModel.serialNo];
            }
            
            if ([equipManagerModel.alias length]==0) {
                cell.otherNameLab.text=[NSString stringWithFormat:@"别名：无"];
            }else{
                cell.otherNameLab.text=[NSString stringWithFormat:@"别名：%@",equipManagerModel.alias];
            }
            
            cell.statusLabel.text=[NSString stringWithFormat:@"状态：%@",[self resultStatus:orderInfoModel]];
            cell.statusLabel.textColor=kNavigationBarColor;
            
            cell.troubleTypeLabel.text=[NSString stringWithFormat:@"故障类型：%@",[self resultString:orderInfoModel.classificationId]];
            cell.orderNoLab.text=[NSString stringWithFormat:@"订单编号：%@",orderInfoModel.erpOrderNo];
            cell.timeLabel.text=[NSString stringWithFormat:@"报修日期：%@",orderInfoModel.createTime];
        }

        return cell;
    }
    QLMIntroManDetailTabCell *cell=[QLMIntroManDetailTabCell cellWithTableView:tableView];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    if (serviceInfoModel.data.count!=0) {
        QLMServiceDetailModel *serDetailModel=[[QLMServiceDetailModel alloc] initWithDictionary:serviceInfoModel.data[indexPath.row] error:nil];
        
        NSString *customerEvaluationNumber=nil;
        if (serDetailModel.customerEvaluationNumber.length==0) {
            customerEvaluationNumber=@"无";
        }else{
            customerEvaluationNumber=serDetailModel.customerEvaluationNumber;
        }
        NSString *scoreStr=[NSString stringWithFormat:@"用户评价：%@",customerEvaluationNumber];
        
        NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:scoreStr];
        [aString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xffb910) range:NSMakeRange(5, scoreStr.length-5)];
        
        NSString *levelStr=[NSString stringWithFormat:@"技能星级：%@",serDetailModel.servicerLevelNum];
        NSMutableAttributedString *bString=[[NSMutableAttributedString alloc] initWithString:levelStr];
        [bString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xffb910) range:NSMakeRange(5, levelStr.length-5)];
        
        cell.customerScoreLabel.attributedText=aString;
        cell.techScoreLabel.attributedText=bString;
        
        [cell.compaynameBtn setTitle:serDetailModel.companyName forState:UIControlStateNormal];
        cell.usernameLabel.text=serDetailModel.servicerUserName;
        
        NSString *picStr=[NSString stringWithFormat:@"%@%@",kBaseImageUrl,serDetailModel.iconPath];
        [cell.userImageView sd_setImageWithURL:[NSURL URLWithString:picStr] placeholderImage:[UIImage imageNamed:@"header"]];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (tableView.tag!=666) {
        if (orderListArrModel.orders.count==0) {
            return 0;
        }
        if (section==orderListArrModel.orders.count-1) {
            return 0;
        }
        return 5;
    }
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView.tag!=666) {
        if (orderListArrModel.orders.count==0) {
            return 0.1;
        }
        if (section==0) {
            return 34;
        }
        return 0.1;
    }
    return 34;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 44)];
    headerView.backgroundColor=[UIColor whiteColor];
    
    NSString *btnTitle=@"服务工程师";
    NSInteger btnTag=4001;
    if (tableView.tag!=666) {
        btnTitle=@"报修订单";
        btnTag=4000;
    }
    CGRect rightButtonRect=CGRectMake(kScreen_width-60-10, 5, 60, 24);
    UIButton *rightButton=[self acreatButton:rightButtonRect title:[NSString stringWithFormat:@"查看更多"] image:@"next"];
    rightButton.tag=btnTag;
    [rightButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
    rightButton.titleLabel.font=[UIFont systemFontOfSize:16.0f];
    rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, rightButton.frame.size.width - rightButton.imageView.frame.size.width, 0, 0);
    rightButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10-(rightButton.frame.size.width - rightButton.imageView.frame.size.width ), 0, 10);
    rightButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    
    CGRect leftButtonRect=CGRectMake(10, 5, 160, 24);
    UIButton *newsButton=[self acreatButton:leftButtonRect title:btnTitle image:@"icon"];
    newsButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    newsButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    newsButton.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    newsButton.titleLabel.font=[UIFont systemFontOfSize:18.0f];
    if (tableView.tag!=666) {
        if (section==0) {
            [headerView addSubview:rightButton];
            [headerView addSubview:newsButton];
        }
    }else{
        [headerView addSubview:rightButton];
        [headerView addSubview:newsButton];
    }
    return headerView;
}

#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (tableView.tag!=666) {
        if (orderListArrModel.orders.count!=0) {
            QLMOrderListInfoModel *orderInfoModel=[[QLMOrderListInfoModel alloc] initWithDictionary:orderListArrModel.orders[indexPath.section] error:nil];
            
            QLMBXOrderDetailVC *bxOrderDetailVC=[QLMBXOrderDetailVC new];
            bxOrderDetailVC.repairOrderId=orderInfoModel.repairOrderId;
            bxOrderDetailVC.resultInfoModel=orderInfoModel;
            self.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:bxOrderDetailVC animated:YES];
            self.hidesBottomBarWhenPushed=NO;
        }
    }else{
        QLMServiceDetailModel *serDetailModel=[[QLMServiceDetailModel alloc] initWithDictionary:serviceInfoModel.data[indexPath.row] error:nil];
        
        QLMServiceManDetailVC *serDetailVC=[QLMServiceManDetailVC new];
        serDetailVC.serDetailModel=serDetailModel;
        serDetailVC.isScanInfoBool=YES;
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:serDetailVC animated:YES];
        self.hidesBottomBarWhenPushed=NO;
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
